# 定义路径变量
CUR_DIR := $(shell pwd)
BUFFER_DIR := $(CUR_DIR)/../Buffer
INCLUDE_DIR := $(BUFFER_DIR) $(CUR_DIR)

# 编译器与选项
CXX := g++
CXXFLAGS := -std=c++11 -Wall -Wextra -O2
INCLUDES := $(addprefix -I, $(INCLUDE_DIR))
LIBS := -lpthread

# 源文件与目标文件
LOG_SRC := $(CUR_DIR)/log.cpp
BLOCKQUEUE_SRC := $(CUR_DIR)/blockqueue.h  # 模板类无需编译，仅需包含
TEST_SRC := $(CUR_DIR)/log_test.cpp
BUFFER_SRC := $(BUFFER_DIR)/buffer.cpp

# 目标文件
LOG_OBJ := $(LOG_SRC:.cpp=.o)
BUFFER_OBJ := $(BUFFER_SRC:.cpp=.o)
TEST_OBJ := $(TEST_SRC:.cpp=.o)

# 可执行文件
TEST_EXEC := $(CUR_DIR)/log_test

all: $(TEST_EXEC)

$(TEST_EXEC): $(LOG_OBJ) $(BUFFER_OBJ) $(TEST_OBJ)
	$(CXX) $(CXXFLAGS) $(INCLUDES) $^ $(LIBS) -o $@

%.o: %.cpp
	$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@

clean:
	rm -f $(CUR_DIR)/*.o $(BUFFER_DIR)/*.o $(TEST_EXEC)
	rm -rf ./test_log  # 清理测试生成的日志文件